package adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.hutoubenjg.R;

import java.util.List;

import bean.TopicListlBean;
import util.utls.AutoResizeTextView;
import util.utls.Const;
import util.utls.XImageLoader;

/**
 * 我的帖子列表
 */
public class TieZiMeAdapter extends android.widget.BaseAdapter{
    List<TopicListlBean.TopicList> datas;
    int position;
    Activity context;

    public TieZiMeAdapter(Activity context, List<TopicListlBean.TopicList> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_my_tiezi, null);
            holder.tiezi_time = (AutoResizeTextView) convertView.findViewById(R.id.tiezi_time);
            holder.tiezi_title = (TextView) convertView.findViewById(R.id.tiezi_title);
            holder.tiezi_content = (TextView) convertView.findViewById(R.id.tiezi_content);
            holder.tiezi_img = (ImageView) convertView.findViewById(R.id.tiezi_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tiezi_time.setText(datas.get(position).getCreate_time_desc());
        holder.tiezi_title.setText(datas.get(position).getTitle());
        holder.tiezi_content.setText(datas.get(position).getContent());
        if (datas.get(position).getImg().size()>=1){
            holder.tiezi_img.setVisibility(View.VISIBLE);
            XImageLoader.load(Const.IMAGE_HEAD + datas.get(position).getImg().get(0), holder.tiezi_img);
        }else{
            holder.tiezi_img.setVisibility(View.GONE);
        }

        return convertView;
    }
    public static class ViewHolder {
        TextView tiezi_title,tiezi_content;
        AutoResizeTextView tiezi_time;
        ImageView tiezi_img;

    }
}
